<?php

namespace bee;

// define("PANNEL_WRAP_NODE",     0);
// define("PANNEL_WRAP_DIV",      1);
// define("PANNEL_WRAP_TABLE",    2);
// define("PANNEL_WRAP_TD",       3);
// define("PANNEL_WRAP_SPAN",     4);

/**
 * NE KORISTITI F U C K I N __parent izaziva crash PHP a prilikom serijalizacije (vjerojatno zbog rekurzivnih veza)
 * @author dzelenika
 * ova klasa se koristi za ugnježđene webPanele pošto ne sadrži dispatcher, app i dsdoc izbjegnute su rekurzivne veze
 *
 */
abstract class webPaneLevel2 extends object
{
  public    $__withEvents      = true;
  public    $__caption         = "w e b P a n e";
  public    $__width           = 500;
  public    $__height          = 100;
  public    $__wrapper         = PANNEL_WRAP_DIV;
  public    $__name            = "webPane";
  public    $__visible         = true;

  protected $__dispatcher;
  protected $__DSDoc;
  protected $__app;
  //public    $__parent;  //

  public function __construct()
  {// $this->initializeMe();
/*
    $this->__dispatcher        = dispatcher::getInstance();

    $this->__DSDoc             = XMLDataHub::getInstance();
    $this->__app               = app::getInstance();
    $this->__dispatcher->addObject($this);// možda vratiti u 35???
    */
    dispatcher::getInstance()->addObject($this);

  }

  public function __wakeup()
  {
    //$this->initializeMe();
/*
    $this->__dispatcher        = dispatcher::getInstance();

    $this->__DSDoc             = XMLDataHub::getInstance();
    if(!$this->__app)
    { $this->__app             = app::getInstance();
    }
    $this->__dispatcher->addObject($this); // možda vratiti u46
    //static::$__app           = app::getInstance();
*/
    dispatcher::getInstance()->addObject($this);
  }

  private function initializeMe()
  {
/*
    if($this)
    { $this->__dispatcher      = dispatcher::getInstance();
      $this->__dispatcher->addObject($this);
      $this->__DSDoc           = XMLDataHub::getInstance();
      if(!$this->__app)
      { $this->__app             = app::getInstance();
      }
    }
*/
  }

  public function onCreate($evt)
  { //die(": 1. kreiram :");
  }

  public function onLoad($evt)
  { //die(": 2. učitavam :");
  }

  public function doEvents($evt)
  { //die(": 3. događaji :");
  }

  public function onDraw($evt)
  {
    $this->fillDSDoc();
    //die(": 4 . crtam :");
    //print_r($this);
    //

  }

  public function unLoad($evt)
  { //die(": 5. zatvaram :");
  }

  public function fillDSDoc($fillVar = "")
  {
    $dsDoc = XMLDataHub::getInstance();
    if($fillVar)
    { //$this->__DSDoc->setVariable($fillVar, $this->value);
      $dsDoc->setVariable($fillVar, $this->value);
    }

    //die (print_r($this, true));
    $dsDoc->setObject("/form/widgets/" . $this->__name, $this);
    //$this->__DSDoc->setObject("/form/widgets/" . $this->__name, $this);
  }
}